package com.x.erp.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.GateDao;
import com.x.erp.model.Gate;
import com.x.erp.rpc.GateRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 道闸信息服务
 */
@Component
@Service(interfaceName = "com.x.erp.rpc.GateRpcService", timeout = 60000)
public class GateService extends BaseService implements GateRpcService {

	@Autowired
	private GateDao gateDao;// 道闸信息DAO

	/**
	 * 查询道闸信息列表
	 * 
	 * @param gate
	 * @return
	 */
	@Override
	public List<Gate> selectGateList(Gate gate) {
		try {
			return gateDao.selectGateList(gate);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 查询道闸信息数量
	 * 
	 * @param gate
	 * @return
	 */
	@Override
	public int selectGateNum(Gate gate) {
		try {
			return gateDao.selectGateNum(gate);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 新增道闸信息
	 * 
	 * @param gate
	 * @return
	 */
	@Override
	public Gate insertGate(Gate gate) {
		try {
			gate.setGateCreateTime(this.getDate(0));
			return this.insert(gate);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 修改道闸信息
	 * 
	 * @param gate
	 * @return
	 */
	@Override
	public int updateGate(Gate gate) {
		try {
			return this.update(gate);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

}
